<template>
  <div>
    {{ text }}
  </div>
</template>

<script>
export default {
  name: "el-column-input-table",
  formComponents: "table",
  props: {
    row: [Object],
    rowKey: [String],
    column: {
      type: Object,
    }
  },
  data() {
    return {
      text: "",
      tempData: null,
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      if (!this.column) {
        this.setDefaultValue()
      } else if (!this.column.formatter) {
        this.setDefaultValue()
      } else if (!this.column.onLoad) {
        this.setDefaultValue()
      } else {
        let temp = {};
        temp.value = this.row[this.rowKey];
        if (this.tempData) {
          this.formatterData(this.tempData);
          return;
        }
        this.column.onLoad(temp, this.formatterData)
      }
    },
    formatterData(data) {
      if (!data) return
      this.tempData = data;
      let resultData = this.column.formatter(data);
      if (!resultData) return;
      this.text = resultData;
    },
    setDefaultValue() {
      this.text = this.row[this.rowKey];
    }
  }
}
</script>

<style scoped>

</style>
